package com.test.shiver.controller;

import com.test.shiver.service.UserService;
import com.test.shiver.service.impl.UserServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

public class UserDeleteServlet extends HttpServlet {

    private UserService userService = new UserServiceImpl();

    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        String id = request.getParameter("id");

        int ret = userService.removeUserById(Integer.parseInt(id));

        String msg;
        if(ret != -1){
            msg = "操作成功";
        }else{
            msg = "操作失败";
        }

        request.setAttribute("msg",msg);

        response.sendRedirect(request.getContextPath()+"/userList");
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
            this.doPost(request,response);
    }
}
